public class Demo03 {
    //懒汉模式
    public static void main(String[] args) {
        SingletonLazy singletonLazy = new SingletonLazy();
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                SingletonLazy instance = singletonLazy.getInstance();
                System.out.println(instance);
            });
            thread.start();
        }
    }
}

class SingletonLazy {
    private static SingletonLazy instance;
    public SingletonLazy() {
    }
    public static SingletonLazy getInstance() {
        if (instance == null) {
            synchronized (SingletonLazy.class) {
                if (instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }
}